package br.fatec.model.dao;

import java.util.HashMap;

import br.fatec.model.entity.Formula_Materiaprima;
import br.fatec.util.Globals;
import br.fatec.util.Persistencia;

public class Formula_MateriaprimaDao {
	private Persistencia persis;

	public Formula_MateriaprimaDao() {
		Globals globals = Globals.getInstance();

		this.persis = globals.getPersistencia();
	}

	public void cadastrar(Formula_Materiaprima formulaMateriaprima)
			throws Exception {
		persis.cadastrar(formulaMateriaprima);
	}

	public void alterar(Formula_Materiaprima formulaMateriaprima)
			throws Exception {
		persis.alterar(formulaMateriaprima);
	}
	
	public void excluir(Formula_Materiaprima formulaMateriaprima)
			throws Exception {
		persis.excluir(formulaMateriaprima.getClass(),
				formulaMateriaprima.getCodigo());
	}

	public Formula_Materiaprima consultar(Formula_Materiaprima formulaMateriaprima)
			throws Exception {
		String query = "select * from formula_materiaprima where formula = :formula and materia_prima = :materia_prima";
		
		HashMap<String, Object> parametros = new HashMap<String, Object>();
		parametros.put("formula", formulaMateriaprima.getCodigo().getFormula().getCodigo());
		parametros.put("materia_prima", formulaMateriaprima.getCodigo().getMateriaPrima().getCodigo());

		return (Formula_Materiaprima)persis.consultar(formulaMateriaprima.getClass(), query, parametros);
	}
}
